package graphic.dialogs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.IOException;

import javax.swing.JLabel;
import javax.swing.JPanel;

import core.Server;

public class ServerStopDialog extends AbstractDialog
{

	public ServerStopDialog()
	{
		super("Server Stopping", "Stop Server", 300, 150);
	}

	@Override
	public void createPanel()
	{
		super.setPanel(new JPanel(new GridBagLayout()));
		
		JPanel panel = super.getPanel(); 
		
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
		c.anchor = GridBagConstraints.CENTER;
		c.insets = new Insets(5, 10, 5, 10);
		
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = 2;
		panel.add(new JLabel("Are you sure to stop the server?"), c);
		
		c.gridx = 0;
		c.gridy = 1;
		c.gridwidth = 1;
		panel.add(super.getOkButton(), c);

		c.gridx = 1;
		c.gridy = 1;
		panel.add(super.getExitButton(), c);
	}

	@Override
	public boolean checkOkFunction(){ return true; }

	@Override
	public void okFunction()
	{
		try { Server.getInstance().stopServer(); } catch (IOException e) { super.dispose(); }
		super.dispose();
	}
}
